package example.com.zcq.mymj.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

import example.com.zcq.mymj.R;
import example.com.zcq.mymj.bean.LishiJinRi;

/**
 * @author zcq
 * @package example.com.zcq.mymj.Adapter
 * @fileName MyMj
 * @description: 这个类的描述
 * @org 融信通达科技有限公司
 * @email @163.com
 * @date 2018/11/23  16:45
 */
public class LiShiAdapter extends RecyclerView.Adapter<LiShiAdapter.ViewHolder> {
    private List<LishiJinRi.ResultBean> mResultBeanList;
    private Context context;

    public LiShiAdapter(Context context, List<LishiJinRi.ResultBean> mResultBeanList1) {
        mResultBeanList = mResultBeanList1;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.lishijinri_item, viewGroup,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int i) {
        LishiJinRi.ResultBean data = mResultBeanList.get(i);
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.new_pic)                //加载成功之前占位图
                .error(R.drawable.new_pic)
                .fitCenter();
        //
        Glide.with(context)
                .asBitmap()
                .load(data.getPic())
                .apply(options)
                .into(viewHolder.mIvPic);
        viewHolder.mTvTitle.setText(data.getDes());
        viewHolder.mTvTime.setText(data.getLunar());


    }

    @Override
    public int getItemCount() {
        if (mResultBeanList.size() != 0) {
            return mResultBeanList.size();

        } else
            return 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        View view;
        ImageView mIvPic;
        TextView mTvTitle;
        TextView mTvTime;

        ViewHolder(@Nullable View view) {
            super(view);
            this.view = view;
            this.mIvPic = (ImageView) view.findViewById(R.id.iv_pic);
            this.mTvTitle = (TextView) view.findViewById(R.id.tv_title);
            this.mTvTime = (TextView) view.findViewById(R.id.tv_time);
        }
    }


}
